package cn.com.bdqn.dao;

import cn.com.bdqn.entity.CstCustomer;
import cn.com.bdqn.entity.CstLost;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface CstLostDao {

    public List<Map> queryByLike(@Param("custManagerName") String custManagerName, @Param("custName") String custName, @Param("lstStatus") String lstStatus);

    @Select("select * from cst_lost a,cst_customer b\n" +
            "where a.lst_cust_no = b.cust_no and lst_id = #{value}")
    public Map queryByLstId(Long lstId);

    public int updateCstLost(CstLost cstLost);

    //查询俩个月没有下单的客户
    @Select("select * from cst_customer where \n" +
            "cust_no not in(\n" +
            "\tselect odr_cust_no from orders \n" +
            "\t\twhere datediff(now(),odr_date)<60\n" +
            ") and cust_no in(select odr_cust_no from orders)")
    List<CstCustomer> queryOutCustomer();

    //新增客户流失信息
    @Insert("insert into cst_lost(lst_id,lst_cust_no,lst_cust_name,lst_cust_manager_id,lst_cust_manager_name,lst_last_order_date,lst_status) values (default,#{lstCustNo},#{lstCustName},#{lstCustManagerId},#{lstCustManagerName},#{lstLastOrderDate},#{lstStatus})")
    int addLost(CstLost lost);
}
